﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JeanFish.Blog
{
    public class Paging : Tuple<int, int>
    {
        public const int DefaultPageSize = 10;
        private readonly int requiredTotal = 0;
        private int actualTotal = 0;

        public int Size { get { return base.Item1; } }
        public int Index { get { return base.Item2; } }
        public Paging(int pageIndex, int pageSize = DefaultPageSize)
            : base(pageSize, pageIndex) {
                requiredTotal = pageSize * pageIndex + pageSize;
                this.ActualIndex = pageIndex;
            }
        public int Total { get { return actualTotal; } set {

            this.actualTotal = value;
            if (this.actualTotal < requiredTotal)
            {
                this.ActualIndex = this.actualTotal / this.Size;
            }
        } }
        public int ActualIndex { get;private set; }
    }
}